<?php
// news/Form/News.php

class Form_News extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {	
//    	die_a($params);
    	$this->setMethod('POST');
    	if ($params['action'] === 'new')
		{
            $this->setAttrib('id', 'new_news');
//            $e = $params['view']->hvnUrl(array('module' => 'news', 'action'=>'new', 'view' => $this->view));
//        	$this->setAction($e);
		}
		else
    	{
            $this->setAttrib('id', 'edit_news');
//            $e = $params['view']->hvnUrl(array('module' => 'news', 'action'=>'edit', 'view' => $this->view));
//        	$this->setAction($e);
		}	
		
		$this->setAction($params['action_url']);
		
    	$filterHtmlBody = new Clu_Filter_HtmlBody();
		$this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
		
		//add title
        $title = new Zend_Form_Element_Text('title', 
                         array('disableLoadDefaultDecorators' => true,
//                             'required'   => true,             
                               'class' => 'inputText'));
        
        $title->addDecorators($this->_noDecorator);
        $this->addElement($title);
        
        //add keywords
        $keywords = new Zend_Form_Element_Text('keywords', 
                         array('disableLoadDefaultDecorators' => true,
//                             'required'   => true,             
                               'class' => 'inputText'));
        $keywords->addDecorators($this->_noDecorator);
        $this->addElement($keywords);
        
        //add category
        $category = new Zend_Form_Element_MultiCheckbox('category',  
                         array('disableLoadDefaultDecorators' => true,
                         'required'   => true,  
                         ));
    	$mCategory = new category_Model_Category();
        $mCategory->setTables('news');
        foreach($mCategory->getRootType('Root_News') as $e) {
            $category->addMultiOption($e['id'], $e['name']);
        }             
        $category->addDecorators($this->_noDecorator);
        $this->addElement($category);
        
        if ($params['action'] === 'new')
		{
			if(strpos ($params['userPermissions'], 'set status news') === false)
			{
                //add check captcha
                $elementCaptcha = 
                				   new Zend_Form_Element_Captcha('captcha_new_news',
                                   array('captcha' => 'Image','captchaOptions' =>
                                   array(
                                        'captcha' => 'Image',
                                        'wordLen' => 4,
                                        'timeout' => 300,
                                        'imgDir'  =>APP_PATH.'/public/captcha',
                                        'imgUrl' => '/public/captcha/',
                                        'width' => 175,
                                        'height' => 60,
                                        'font' => APP_PATH.'/public/captcha/font/tahoma.ttf',
                                        'DotNoiseLevel' => 10,  
                                        'LineNoiseLevel' => 1,
                                        'expiration' => 3,
                                        'gcFreq' => 1))
                );
                $elementCaptcha->setLabel(t(39).':')
                               ->setAttrib('id','captcha_new_newsImage')
                           	   ->setRequired(true);
                $this->addElement($elementCaptcha);
			}
            
            //add language
            $newsLanguage = new Zend_Form_Element_Select('newsLanguage',  
                             array('disableLoadDefaultDecorators' => true,
    //                                'required' => true
                             )); 
            $newsLanguage->addMultiOption('vi',t(40))
                       ->addMultiOption('en',t(41))
                       ->addMultiOption('cn',t(42))
                       ->addMultiOption('jp',t(43))
                       ->addDecorators($this->_noDecorator);
            $this->addElement($newsLanguage);
		}    
        
		//status
        //only the user with permission can set the status of the event.
        //else, it will be null and default values 'queued' will be inserted to DB
        if (strpos ($params['userPermissions'], 'set status news'))
        {
            $status = new Zend_Form_Element_Select('status',  
                             array('disableLoadDefaultDecorators' => true));
            $status->addMultiOption('featured ',t(33))
            	   ->addMultiOption('published',t(34))
                   ->addMultiOption('queued',t(35))
                   ->addMultiOption('unpublished',t(36))
                   ->addMultiOption('deleted',t(37))
                   ->addDecorators($this->_noDecorator);
    		$status->setValue('published');
            $this->addElement($status);
        }
        
        //add body 
        $body = new Clu_Form_Element_FckEditor('body', array(
        		'fckOptions' => array (
        						'Height' => 500,
        						'Width'  => 650,
        						'ToolbarSet' => 'Full'
        					)
       			 )
        );
        $body->setLabel(t(303));
        $body->addFilter($filterHtmlBody ); //TODO: if our people, maybe we don't need to filter
        $this->addElement($body);
        
        // add the submit button
		if ($params['action'] === 'new')
    		$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                           'label' => t(58) ));
      	else
      	$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
        
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
}
?>